#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : aimix
@File    : humanize_worker.py
@IDE     : PyCharm
@Author  : admin
@Date    : 2025/4/24 16:33
"""
import json
import traceback
from PyQt5.QtCore import QThread, pyqtSignal
from utils.tools import request
from config import Config


class HumanizeWorker(QThread):
    """去Ai化"""
    result = pyqtSignal(dict)
    failed = pyqtSignal(Exception)


    def __init__(self, content, headers, parent=None):
        super(HumanizeWorker, self).__init__()
        self.content = content
        self.headers = headers


    def run(self):
        try:
            data = {
                "c": self.content,
            }
            headers = {'Content-Type': 'application/json'}
            response = request(f'{Config.Host}/tool/humanize/', method='POST', data=json.dumps(data), headers=headers)
            data = response.json()
            self.result.emit(data.get("data").get("content"))
        except Exception as e:
            traceback.print_exc()
            self.failed.emit(e)
